<template>
  <div class="page">
    <!-- 搜索区域 开始 -->
    <div class="el_card_box">
      <el-form :inline="true" size="small" :model="formInline" class="search_form">
        <el-form-item label="注册平台：">
          <!-- <el-select v-model="formInline.platforms" filterable clearable>
            <el-option v-for="(item, index) in cityList" :key="index" :label="item.name" :value="item.code"></el-option>
          </el-select> -->
          <PlatformSelect v-model="formInline.platforms"></PlatformSelect>
        </el-form-item>
        <!-- <el-form-item label="关联医院：">
          <hospital-select v-model="formInline.hospital"></hospital-select>
        </el-form-item> -->
        <el-form-item label="注册时间：">
          <el-date-picker v-model="formInline.registerTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最后登录时间：">
          <el-date-picker v-model="formInline.loginTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="关键词：">
          <el-input v-model="formInline.term" placeholder="昵称或电话"></el-input>
        </el-form-item>
      </el-form>
      <div class="search_btn_box">
        <el-button type="primary" size="small" @click="onSearch">筛选</el-button>
        <el-button type="default" size="small" @click="rest">清空筛选</el-button>
      </div>
    </div>
    <!-- 搜索区域 end -->

    <!-- 表格 开始 -->
    <div class="table_box">

      <el-table ref="elTable" class="el_table" size="small" :data="tableData">
        <el-table-column prop="channelName" label="用户信息" width="400px">
          <template slot-scope="{row}">
            <tab-user :user="showFormatter(row)" :disabled="true">
              <template slot="avatar">
              <li-image :src="row.avatar" :lazy-load="false" />
              </template>
            </tab-user>
          </template>
        </el-table-column>
        <el-table-column prop="platform" label="注册平台" show-overflow-tooltip />
        <el-table-column prop="reason" label="注册原因" show-overflow-tooltip />
        <!-- <el-table-column prop="hospitalName" label="关联医院" show-overflow-tooltip /> -->
        <el-table-column prop="createdDate" label="注册时间" show-overflow-tooltip />
        <el-table-column prop="loginTimes" label="登录次数" show-overflow-tooltip />
        <el-table-column prop="lastLoginTime" label="最后登录时间" show-overflow-tooltip />
        <el-table-column prop="lastLoginIp" label="最后登录IP" show-overflow-tooltip />
      </el-table>
      <div class="pagination_list">
        <el-pagination background layout="sizes, total,prev, pager, next, jumper" :total="pageTotal" :page-size="pageSize" :page-sizes="pageSizes" :current-page.sync="pageNumber" @current-change="getList" @size-change="changePageSize" />
      </div>
    </div>
    <!-- 表格 end -->
  </div>
</template>
  
<script>
import { showToast, showModal, deepClone } from "@/common/util";
import { GET_PLATFORM_CCUSER_SEARCH } from '@/http/consumer'
import PlatformSelect from '@/components/select/platform.vue'
export default {
  components:{
    PlatformSelect
  },
  data() {
    return {
      formInline: {},
      tableData: [],
      pageTotal: 0,
      pageNumber: 1,
      pageSizes: [10, 20, 50, 100],
      pageSize: 20,
      loading: false,
    };
  },
  mounted() {
    this.getList();
    //this.getCity();
  },
  methods: {
    /** 重置 */
    rest() {
      this.formInline = {};
      this.getList();
    },

    /** 每页展示 */
    changePageSize(e) {
      this.pageSize = e;
      this.getList();
    },

    /** 获取参数 */
    getParams() {
      let oParams = deepClone(this.formInline);
      let o = oParams.registerTime || []
      let m = oParams.loginTime || []

      if(o && o.length){
        oParams.registerBeginTime = o[0]
        oParams.registerEndTime = o[1]
      }

      if(m && m.length){
        oParams.lastLoginBeginTime = m[0]
        oParams.lastLoginEndTime = m[1]
      }

      delete oParams.registerTime
      delete oParams.loginTime

      oParams.pageNumber = this.pageNumber;
      oParams.pageSize = this.pageSize;
      return oParams;
    },

    /** 获取列表 */
    getList() {
      let _this = this;
      let oParams = this.getParams();
      GET_PLATFORM_CCUSER_SEARCH(oParams).then((res) => {
        let obj = res.data || {};
        _this.tableData = obj.list || [];
        _this.pageTotal = obj.totalElements;
      });
    },

    // 格式化医院数据
    showFormatter(row) {
      if (!row) {
        return {};
      }
      let o = deepClone(row)
      o.customerName = row.username;
      o.customerPhone = row.phone;
      return o;
    },

    // 搜索
    onSearch(){
      this.pageNumber = 1;
      this.getList()
    }


  },
};
</script>
  
<style lang="scss" scoped>
@import "@/assets/style/customer/index.scss";
</style>
  